﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AntikCompta.Data;

namespace AntikCompta
{
    public partial class CouleurLotWnd : Form
    {
        public CouleurLotWnd(String aRefLot)
        {
            InitializeComponent();
            txt_lot.Text = aRefLot;
            txt_sample.Text = aRefLot;

            Color couleur;
            if (CouleurLotMng.GetObject().GetColor(aRefLot, out couleur))
                p_sample.BackColor = couleur;
            else
                p_sample.BackColor = Color.White;
        }

        private void bt_changer_Click(object sender, EventArgs e)
        {
            ColorDialog cd = new ColorDialog();
            if (cd.ShowDialog() == DialogResult.OK)
                p_sample.BackColor = cd.Color;
        }

        private void bt_supprimer_Click(object sender, EventArgs e)
        {
            p_sample.BackColor = Color.White;
        }

        private void bt_enregistrer_Click(object sender, EventArgs e)
        {
            if (p_sample.BackColor == Color.White)
                CouleurLotMng.GetObject().DelColor(txt_lot.Text);
            else
                CouleurLotMng.GetObject().SetColor(txt_lot.Text, p_sample.BackColor);

            DialogResult = DialogResult.OK;
            Close();
        }

        private void bt_annuler_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}
